<template>
  <div class="switchButtonContainer" v-show="this.show !== 'gone'">
    <div
      class="titleContainer"
      v-show="this.show !== 'invisible'"
      :class="{ outline: this.showDisable }"
    >
      <div class="topTitleContainer">
        <div class="title">{{ this.title }}</div>
        <img
          class="tipImg"
          src="../../assets/img/light/ic_warmwind_show_tip.png"
          v-show="showTipImg"
          @click="clickTipBtn"
        />
      </div>
      <div class="state" v-show="this.isOn">
        {{ $t("btnTitle.on") }}
      </div>
    </div>
    <div class="rightContainer" :class="{ outline: this.showDisable }">
      <div class="switchContainer">
        <MySwitch
          class="switch"
          :checkedProps="this.isOn"
          @change="switchValueChanged"
          v-show="this.show !== 'invisible'"
        >
        </MySwitch>
      </div>
      <div
        class="rightMask"
        v-show="this.showDisable"
        @click="clickDisable"
      ></div>
    </div>
  </div>
</template>
<script>
import MySwitch from "./MySwitch.vue";
export default {
  components: {
    MySwitch,
  },
  props: {
    titleProp: {
      type: String,
      default: "",
    },
    showPro: {
      type: String,
      default: true,
    },
    showDisablePro: {
      type: Boolean,
      default: false,
    },
    isOnProp: {
      type: Boolean,
      default: false,
    },
    showTipImgPro: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      show: "visible", //控件是否可见：visible-可见 invisible-不可见，但仍占据空间 gone-不可见，也不占据空间
      showDisable: false, //按钮是否显示不可用
      isOn: false, //按钮是否开启，在这里是指switch开关是否开启
      title: "", //按钮标题
      showTipImg: false, //是否显示tip小图标，点击这个图标会就近弹出说明文本框
    };
  },
  mounted() {
    this.show = this.showPro;
    this.showDisable = this.showDisablePro;
    this.isOn = this.isOnProp;
    this.title = this.titleProp;
    this.showTipImg = this.showTipImgPro;
  },
  computed: {
    getButtonImage: function () {
      return this.imgStr;
    },
  },
  watch: {
    showPro(newVal) {
      this.show = newVal;
    },
    showDisablePro(newVal) {
      this.showDisable = newVal;
    },
    isOnProp(newVal) {
      this.isOn = newVal;
    },
    showTipImgPro(newVal) {
      this.showTipImg = newVal;
    },
  },
  methods: {
    clickTipBtn() {
      this.$emit("clickTip");
    },
    switchValueChanged(value) {
      this.isOn = value;
      this.$emit("switchValueChanged", value);
    },
    clickDisable() {
      console.log("SwitchButton: clickDisable");
      this.$emit("clickDisable");
    },
  },
};
</script>
<style scoped>
.switchButtonContainer {
  height: 64px;
  width: 100%;
  background-color: var(--current-card-background-color);
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  /* background: #ffff00; */
}

/* .switchButtonContainer:active {
  opacity: 0.3;
} */

.switchButtonContainer .titleContainer {
  margin-left: 16px;
  flex-direction: column;
}

.switchButtonContainer .titleContainer .state {
  font-size: 12px;
  color: var(--current-second-title-color);
  margin-top: 2px;
}

.switchButtonContainer .titleContainer .topTitleContainer {
  display: flex;
  flex-direction: row;
  align-items: center;
}

.switchButtonContainer .titleContainer .topTitleContainer .title {
  font-size: 16px;
  color: var(--current-primary-color);
}

.switchButtonContainer .titleContainer .topTitleContainer .tipImg {
  width: 16px;
  height: 16px;
  margin-left: 4px;
}
.switchButtonContainer .rightContainer {
  width: 40px;
  height: 25px;
  /* background: rgba(255, 0, 0, 0.5); */
  position: relative;
  margin-right: 16px;
}
.switchButtonContainer .rightContainer .rightMask {
  position: absolute;
  z-index: 2;
  width: 100%;
  height: 100%;
  /* background: rgba(0, 255, 0, 0.5); */
}
.switchButtonContainer .rightContainer .switchContainer {
  position: absolute;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  align-items: center;
}
.switchButtonContainer .rightContainer .switchContainer .switch {
  margin-right: 0px;
}

.switchButtonContainerOutline {
  opacity: 0.4;
}
</style>
